import { loadLanguageAsync } from '@/locales';
import { defineStore } from 'pinia';


export const useAppStore = defineStore('app', {
    state: () => {
        return {
            theme: 'dark', // 主题色
            isCollapse: false, // 菜单是否折叠
            isMobile: false, // 是否是移动端
            lang: 'zh-CN', // 默认语言
            _antLocale: {}, // 语言包
        }
    },
    actions: {
        // 切换主题色
        toggleTheme() {
            this.theme = this.theme === 'dark' ? 'light' : 'dark'
        },
        // 切换菜单折叠
        toggleCollapse() {
            this.isCollapse = !this.isCollapse   
        },
        // 切换移动端
        toggleMobile() {
            this.isMobile =!this.isMobile
        },
        // 切换语言
        setLang(lang: string) {
            loadLanguageAsync(lang).then((res) => {
                this.lang = lang;
            })
        }
    },
    getters: {
        getTheme: (state) => state.theme,
        getIsCollapse: (state) => state.isCollapse,
        getIsMobile: (state) => state.isMobile,
        getLang: (state) => state.lang,
    }
})